package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.pojo.dto.*;
import com.tbit.uqbike.object.pojo.vo.GiftCardDetailVO;
import com.tbit.uqbike.object.pojo.vo.GiftCardIncomeVO;
import com.tbit.uqbike.object.pojo.vo.GiftCardTotalDetailVO;
import com.tbit.uqbike.object.pojo.vo.GiftCardTotalIncomeVO;
import com.tbit.common.entity.view.PageResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.GiftCardStatService;
import com.tbit.uqbike.webmanager.util.StringUtil;
import com.tbit.uqbike.webmanager.util.csv.annotations.AsyncDownload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 财务统计-礼品卡金额统计
 *
 * @AUTHOR: wei.xing
 * @DATE: 2022-11-18 08:52
 **/
@RestController
@RequestMapping("/giftCardStat")
public class GiftCardStatController {

    @Autowired
    GiftCardStatService service;

    /**
     * 获取礼品卡金额明细的数据截止时间
     *
     * @param accountIds 区域id 多个用,隔开
     * @return
     */
    @GetMapping("/getDetailLastTime")
    public Result<Long> getDetailLastTime(String accountIds) {
        List<Integer> accountIdList = StringUtil.getIntegerList(accountIds);
        Long updateTime = service.getLastTime(accountIdList);
        return Result.success(updateTime);
    }


    /**
     * 获取礼品卡金额明细的汇总
     *
     * @param dto
     * @return
     */
    @GetMapping("/getTotalDetail")
    public Result<GiftCardTotalDetailVO> getTotalDetail(StatDetailDTO dto) {
        GiftCardTotalDetailVO detailVO = service.getTotalDetail(dto);
        return Result.success(detailVO);
    }


    /**
     * 获取礼品卡金额明细的分页
     *
     * @param dto
     * @return
     */
    @GetMapping("/getDetailPage")
    public Result<PageResult<GiftCardDetailVO>> getDetailPage(StatDetailPageDTO dto) {
        PageResult<GiftCardDetailVO> page = service.getDetailPage(dto);
        return Result.success(page);
    }

    /**
     * 礼品卡金额明细的账单下载
     *
     * @param dto
     * @return
     */
    @AsyncDownload(defaultFileName = "礼品卡金额明细")
    @PostMapping("/exportDetail")
    public Result exportDetail(@RequestBody StatDetailDownloadDTO dto) {
        String url = service.exportDetail(dto);
        return Result.success(url);
    }


    /**
     * 获取礼品卡金额收支明细的汇总
     *
     * @param dto
     * @return
     */
    @GetMapping("/getIncomeTotalDetail")
    public Result<GiftCardTotalIncomeVO> getTotalIncome(GiftCardIncomeDTO dto) {
        GiftCardTotalIncomeVO detailVO = service.getTotalIncome(dto);
        return Result.success(detailVO);
    }

    /**
     * 获取礼品卡金额收支明细的分页
     *
     * @param dto
     * @return
     */
    @GetMapping("/getIncomeDetailPage")
    public Result<PageResult<GiftCardIncomeVO>> getIncomePage(GiftCardIncomePageDTO dto) {
        PageResult<GiftCardIncomeVO> pageResult = service.getIncomePage(dto);
        return Result.success(pageResult);
    }


    /**
     * 礼品卡金额收支明细的账单下载
     *
     * @param dto
     * @return
     */
    @AsyncDownload(defaultFileName = "礼品卡金额收支明细")
    @PostMapping("/exportIncomeDetail")
    public Result exportIncome(@RequestBody GiftCardIncomeDownloadDTO dto) {
        String url = service.exportIncome(dto);
        return Result.success(url);
    }

}
